<template>
  <div>
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()" :label-position="labelPosition" label-width="100px">
      <el-row>
        <el-col :span="12">
          <div class="grid-content bg-purple">
            <el-form-item label="工夹具代码" size="mini">
              <el-input  class="myinput" v-model="dataForm.code" placeholder="工夹具代码" clearable width="50%"></el-input>
            </el-form-item>
          </div>
        </el-col>
        <el-col :span="12">
          <div class="grid-content bg-purple-light">
            <el-form-item label="工夹具序列号" size="mini">
              <el-input class="myinput" v-model="dataForm.seqId" placeholder="工夹具序列号" clearable></el-input>
            </el-form-item>
          </div>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <div class="grid-content bg-purple">
            <el-form-item label="申请人" size="mini">
              <el-input class="myinput" v-model="dataForm.submitName" placeholder="申请人" clearable></el-input>
            </el-form-item>
          </div>
        </el-col>
        <el-col :span="12">
          <div class="grid-content bg-purple">
            <el-form-item label="故障原因" size="mini">
              <el-input class="myinput" v-model="dataForm.repairReason" placeholder="故障原因" clearable></el-input>
            </el-form-item>
          </div>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <div class="grid-content bg-purple-light" >
            <el-form-item label="审批状态" size="mini">
              <el-select class="myinput" v-model="dataForm.status" clearable placeholder="请选择">
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </div>
        </el-col>
        <el-col :span="12">
          <el-form-item label="时间范围" size="mini">
            <div class="block">
              <el-date-picker
                v-model="dataForm.startToEndTime"
                type="datetimerange"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :default-time="['12:00:00']"
                size="mini"
                style="width: 490px">
              </el-date-picker>
            </div>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12" :offset="12">
          <div class="grid-content bg-purple-light">
            <el-form-item size="mini">
              <el-button type="primary" icon="el-icon-search" @click="getDataList()">查询</el-button>
              <!--        <el-button  type="primary" @click="addOrUpdateHandle()">新增</el-button>-->
              <el-button plain icon="el-icon-delete" @click="clearDataForm()">清空</el-button>
              <el-button  type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button>
              <el-button type="info" :disabled="dataList.length <=0">导出本页<i class="el-icon-upload el-icon--right"></i></el-button>
              <el-button type="info" :disabled="dataList.length <=0">导出全部<i class="el-icon-upload el-icon--right"></i></el-button>
            </el-form-item>
          </div>
        </el-col>
      </el-row>

    </el-form>
    <hr style="opacity: 0.3"><br>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;"
      size="mini">
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column>
      <el-table-column
        prop="code"
        header-align="center"
        align="center"
        label="工夹具代码">
      </el-table-column>
      <el-table-column
        prop="seqId"
        header-align="center"
        align="center"
        label="工夹具序列号">
      </el-table-column>
      <el-table-column
        prop="submitName"
        header-align="center"
        align="center"
        label="申请人">
      </el-table-column>
      <el-table-column
        prop="repairReason"
        header-align="center"
        align="center"
        label="故障原因">
      </el-table-column>
      <el-table-column
        prop="submitTime"
        header-align="center"
        align="center"
        label="申请时间">
      </el-table-column>
      <el-table-column
        prop="status"
        header-align="center"
        align="center"
        label="处理状态">
        <template slot-scope="scope">
          <span v-if="scope.row.status === '0'">已同意</span>
          <span v-else>未同意</span>
        </template>
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="150"
        label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">修改</el-button>
          <el-button type="text" size="small" @click="deleteHandle(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="dataForm.pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="dataForm.pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
  </div>
</template>

<script>
import AddOrUpdate from "../scrap/scrapsubmithistory-add-or-update";

export default {
  name: "repairsubmithistory",
  data () {
    return {
      value1:'',
      labelPosition:'left',
      options: [{
        value: 0,
        label: '初审未通过'
      }, {
        value: 1,
        label: '初审通过'
      }, {
        value: 2,
        label: '终审未通过'
      }, {
        value: 3,
        label: '终审通过'
      }],
      dataForm: {
        pageIndex: 1,
        pageSize: 10,
      },
      dataList: [],
      // pageIndex: 1,
      // pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      dataListSelections: [],
      addOrUpdateVisible: false
    }
  },
  components: {
    AddOrUpdate
  },
  computed:{
    // startPickerOptions(){
    //   //选择的日期
    //   let curDate = this.$moment(this.startDate).format("YYYY-MM-DD");
    //   //最小日期
    //   let minDate = this.$moment(this.minTime).format("YYYY-MM-DD");
    //   //前推一天，防止当天日期无法选择
    //   let preTime = this.minTime-24*3600000;
    //   // 如果选择的日期为最小日期，则设置为最小日期的时分秒
    //   let str = "";
    //   if(curDate == minDate){
    //     str = this.$moment(this.minTime).format("HH:mm:ss");
    //   }else{
    //     str = "00:00:00"
    //   }
    //   return {
    //     disabledDate: (time) => {
    //       return time.getTime() < preTime || time.getTime() > this.maxTime;
    //     },
    //     selectableRange: str + " - 23:59:59"
    //   }
    // },
  },
  activated () {
    this.getDataList()
  },
  methods: {
    getDataListByLike(){
      this.$http.post(`http://localhost:10000/gongjiajumain/scrapsubmithistory/getformdata`,this.dataForm)
        .then(res=>{
          console.log(this.dataForm)
          console.log("传输成功")
        })
    },
    //清空表格
    clearDataForm(){
      this.dataForm = {}
    },
    // 获取数据列表
    getDataList () {
      this.dataListLoading = true
      this.$http.post(`http://localhost:10000/gongjiajumain/repairsubmit/list1`,this.dataForm)
        .then(data=>{
          if (data.data && data.data.code === 0) {
            this.dataList = data.data.page.list
            this.totalPage = data.data.page.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
    },
    // 每页数
    sizeChangeHandle (val) {
      this.dataForm.pageSize = val
      this.dataForm.pageIndex = 1
      this.getDataList()
    },
    // 当前页
    currentChangeHandle (val) {
      this.dataForm.pageIndex = val
      this.getDataList()
    },
    // 多选
    selectionChangeHandle (val) {
      this.dataListSelections = val
    },
    // 新增 / 修改
    addOrUpdateHandle (id) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(id)
      })
    },
    // 删除
    deleteHandle (id) {
      var ids = id ? [id] : this.dataListSelections.map(item => {
        return item.id
      })
      this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$http({
          url: "http://localhost:10000/gongjiajumain/scrapsubmithistory/delete",
          method: 'post',
          data: this.$http.adornData(ids, false)
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
                this.getDataList()
              }
            })
          } else {
            this.$message.error(data.msg)
          }
        })
      })
    }
  }
}
</script>
<style lang="scss">
.myinput .el-input__inner {
  width: 490px;
}

</style>

